import pytest

from Config.db_config import ticketDb
from Util.dbutil import DbUtil


@pytest.fixture(scope="class")
def prepareActorData():
    # 初始化数据
    connObj, cursor = DbUtil.openDb(host=ticketDb["host"], port=ticketDb["port"],
                                    user=ticketDb["user"], password=ticketDb["passwd"]
                                    , db=ticketDb["db"])
    sqlList = [
        "insert into tb_actor (actor_name,actor_img,actor_desc,followers,box_office) " \
        "values ('ggb_张三丰',null,'好人',0,0)",
        "insert into tb_actor (actor_name,actor_img,actor_desc,followers,box_office) " \
        "values ('ggb_样定天',null,'好人',0,0)",
        "insert into tb_actor (actor_name,actor_img,actor_desc,followers,box_office) " \
        "values ('ggb_张晓天',null,'好人',0,0)"
    ]
    for sql in sqlList:
        DbUtil.writeDb(sql, cursor)
    # 提交事物
    connObj.commit()

    yield
    # 清理数据
    delSql = "delete from tb_actor where actor_name like 'ggb%'"
    DbUtil.writeDb(delSql, cursor)
    connObj.commit()
    DbUtil.release(cursor, connObj)


@pytest.fixture(scope="class")
def prepareCinemaData():
    pass
